package com.hzdl.car.controller;

import com.hzdl.car.bean.Statistic;
import com.hzdl.car.service.StatisticService;
import com.hzdl.car.util.AJAXResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/statistic")
public class StatisticController {

    @Autowired
    private StatisticService ss;

    @RequestMapping("/statisticAddressInit")
    public String statisticAddressInit(){
        return "/system/statistic/district";
    }

    @RequestMapping("/statisticAddressShow")
    @ResponseBody
    public AJAXResult statisticAddressShow(){
        List<Statistic> sList=ss.countAddress();
        return new AJAXResult(1,sList);
    }

    @RequestMapping("/statisticSalesInit")
    public String statisticSalesInit(){
        return "/system/statistic/sales";
    }

    @RequestMapping("/statisticSalesShow")
    @ResponseBody
    public AJAXResult statisticSalesShow(Integer year){
        List<Statistic> sList=ss.countSales(year);
        Map<String,Object> map = new HashMap<>();
        List<String> name= new ArrayList<>();
        List<Integer> value = new ArrayList<>();
        for(Statistic s : sList){
            name.add(s.getName());
            value.add(s.getValue());
        }
        map.put("name",name);
        map.put("value",value);
        return new AJAXResult(1,map);
    }
    @RequestMapping("/statisticAssisInit")
    public String statisticAssisInit(){
        return "/system/statistic/assistant";
    }

    @RequestMapping("/statisticAssisShow")
    @ResponseBody
    public AJAXResult statisticAssisShow(Integer year){
        List<Statistic> sList=ss.countAssis(year);
        Map<String,Object> map = new HashMap<>();
        List<String> name= new ArrayList<>();
        List<Integer> value = new ArrayList<>();
        for(Statistic s : sList){
            name.add(s.getName());
            value.add(s.getValue());
        }
        map.put("name",name);
        map.put("value",value);
        return new AJAXResult(1,map);

    }





}
